//
//  ImportConclusionView.swift
//  SidebarMenu
//
//  Created by LiangXiaobin on 2017/2/3.
//  Copyright © 2017年 AppCoda. All rights reserved.
//

import UIKit

class ImportConclusionView: UIView {
    var title:UILabel?
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        title = UILabel(frame:CGRect(x:0,y:0,width:frame.width,height:40))
        title?.backgroundColor = baseColor
        title?.textColor = UIColor.white
        title?.font = UIFont.systemFont(ofSize: 18)
        self.addSubview(title!)
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //单图片
    
    func setTitle(tittle:String,url:String)
    {
        self.title?.text = tittle
        let imageView = UIImageView(frame:CGRect(x:0,y:40 + 10,width:self.frame.width,height:self.frame.height - 20 - 40))
        self.addSubview(imageView)
        
    }
    //大图片下面有字
    func setTitle(tittle:String,urlArray:[String],messageArray:[String]) {
        self.title?.text = tittle
        
        
        let a = self.frame.width - 30
        
        let b = a / 2
        
        if urlArray.count > 0 {
            
            for i in stride(from: 0, through: urlArray.count, by: 1) {
                let imageView = UIImageView(frame:CGRect(x:0 + (b + 30) * CGFloat(i),y:40 + 10,width:(self.frame.width - 30) / 2,height:self.frame.height - 10 - 40 - 20))
                self.addSubview(imageView)
                
            }
        }
        if messageArray.count > 0
        {
            for i in stride(from: 0, through: messageArray.count, by: 1) {
                
                
                if i <= 1 {
                 
                    let label = UILabel(frame:CGRect(x:0 + Int((self.frame.width - 20) / 4) * i,y:Int(self.frame.height - 20),width:Int((self.frame.width - 20) / 4),height:20))
                    label.textColor = messageColor
                    label.text = messageArray[i]
                    label.layer.borderWidth = 1
                    label.layer.borderColor = grayColor.cgColor
                    self.addSubview(label)
                }
                else
                {
                    let label = UILabel(frame:CGRect(x:0 + Int((self.frame.width - 20) / 4) * i + 20,y:Int(self.frame.height - 20),width:Int((self.frame.width - 20) / 4),height:20))
                    label.textColor = messageColor
                    label.text = messageArray[i]
                    label.layer.borderWidth = 1
                    label.layer.borderColor = grayColor.cgColor
                    self.addSubview(label)
                }
            }
        }
    
        
    }

    //下面有几行字
    func setTitle(tittle:String,message:[String]) {
        self.title?.text = tittle
        if message.count > 0 {
            
            for i in stride(from: 0, through: message.count, by: 1) {
                
                let label = UILabel(frame:CGRect(x:0 + i % 2 * Int(self.frame.width / 2) ,y:40 + 10 + Int(i / 2) * 40,width:Int(self.frame.width / 2),height:40))
                label.textColor = messageColor
                label.text = message[i]
                label.layer.borderWidth = 1
                label.layer.borderColor = grayColor.cgColor
                self.addSubview(label)
            }
        }
    }
    
    
    //add按钮
    func setTRRLTittle(title:String,url:String)
    {
        self.title?.text = title
        let imageView = UIImageView(frame:CGRect(x:0,y:40 + 10,width:self.frame.width,height:self.frame.height - 20 - 40))
        self.addSubview(imageView)
        
        
        let addBtn = UIButton(type: .system)
        addBtn.frame = CGRect(x:self.frame.width - 10 - 22,y:11,width:22,height:22)
        addBtn.setEnlargeEdgeWithTop(10, right: 20, bottom: 10, left: 10)
        addBtn.addTarget(self, action:#selector(ImportConclusionView.addSomeMessage(sender:)) , for: .touchUpInside)
        addBtn.setBackgroundImage(imaged(name: "btn_add_normal.png"), for: .normal)
        addBtn.isHidden = true
        self.addSubview(addBtn)
        
    }
    
    
    func addSomeMessage(sender:UIButton)
    {
        
    }
    

}
